package net.jueb.sniff4j.impl.http.filter;

import net.jueb.sniff4j.extr.base.AbstractRuntime;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.util.CharsetUtil;

public class HttpRequestFilter extends HttpObjectFilter {
	
	public HttpRequestFilter(Channel fromChannel, Channel toChannel,
			AbstractRuntime runtime) {
		super(fromChannel, toChannel, runtime);
		// TODO Auto-generated constructor stub
	}


	@Override
	protected void showFiltTargetInfo(Object filtTarget) {
		Object object=filtTarget;
		//DefaultFullHttpRequest是DefaultHttpRequest的子类
		if(object instanceof DefaultFullHttpRequest)
		{
			DefaultFullHttpRequest dfr=(DefaultFullHttpRequest)object;
			String type=dfr.getMethod().toString()+dfr.getUri()+"\n";
			log.debug(info+type+getHeadersString(dfr.headers())+"Content:\n"+new String(getContent(dfr),CharsetUtil.UTF_8));
		}else if(object instanceof DefaultHttpRequest)
		{
			DefaultHttpRequest dr=(DefaultHttpRequest)object;
			String type=dr.getMethod().toString()+dr.getUri()+"\n";
			log.debug(info+type+getHeadersString(dr.headers()));
		}else
		{
			log.debug(info+object.toString());
		}
	}
}
